<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Const</title>
</head>

<body>
    <p>1. const 声明后必须立即初始化,且为块级作用域</p>
    <div>
        <pre>
        const PI;   //Uncaught SyntaxError: Missing initializer in const declaration
         PI= 3.14;
         {
            const block = '1'
         }
         console.log(block)  // Uncaught ReferenceError: block is not defined
         </pre
      >
    </div>
    <hr />
    <p>
      2.const 声明的变量“内存地址”不可改变，因此不能重新赋值。
      因此，简单的类型（数值，字符串，布尔值）不可修改值，但是对于复杂类型（对象和数组）
      可以添加属性和数组元素
    </p>
    <div>
      <pre>
          const foo={}; 
          foo.prop = 123;

          const arr=[];
          arr.push(2)    // 1
      </pre>
    </div>
</body>

</html>
<script>
    const PI; //Uncaught SyntaxError: Missing initializer in const declaration
    PI = 3.14; {
        const block = '1'
    }
    console.log(block) //Uncaught ReferenceError: block is not defined
    console.log('--------------------')

    const foo = {};
    foo.prop = 123;

    const arr = [];
    arr.push(2) //1
</script>